package io.kiki.sba.registry.store.jdbc.mapper;

import io.kiki.sba.registry.common.model.elector.Lock;
import io.kiki.sba.registry.store.jdbc.domain.FollowCompeteLockDomain;
import org.apache.ibatis.annotations.Param;


public interface LockMapper {

    /**
     * query by dataCenter and lockName
     *
     * @param dataCenter dataCenter
     * @param lockName   lockName
     * @return DistributeLockInfo
     */
    public Lock queryLock(@Param("dataCenter") String dataCenter, @Param("lockName") String lockName);

    /**
     * compete lock, it will throw exception if lockName existed
     *
     * @param lock lock
     * @throws Exception Exception
     */
    public void competeLockOnInsert(Lock lock) throws Exception;

    /**
     * compete lock with cas
     *
     * @param competeLock competeLock
     */
    public void competeLockOnUpdate(FollowCompeteLockDomain competeLock);

    /**
     * renew lock last update time
     *
     * @param lock lock
     */
    public void ownerHeartbeat(Lock lock);

    /**
     * force reset owner and duration
     *
     * @param lock lock
     */
    public void forceRefresh(Lock lock);
}
